package com.jxw.launcher.view;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.Html;
import android.text.Selection;
import android.text.TextUtils;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.jxw.launcher.R;
import me.jessyan.autosize.AutoSize;

/* loaded from: classes.dex */
public class MyAlertDialog {
    private TextView btn_neg;
    private TextView btn_pos;
    private Context context;
    private Dialog dialog;
    private LinearLayout dialog_Group;
    private ImageView dialog_marBottom;
    private Display display;
    private EditText edittxt_result;
    private ImageView img_line;
    private LinearLayout lLayout_bg;
    private LinearLayout negLL;
    private LinearLayout posLL;
    private TextView txt_msg;
    private TextView txt_title;
    private boolean showTitle = false;
    private boolean showMsg = false;
    private boolean showEditText = false;
    private boolean showLayout = false;
    private boolean showPosBtn = false;
    private boolean showNegBtn = false;

    public MyAlertDialog(Context context) {
        this.context = context;
        this.display = ((WindowManager) context.getSystemService("window")).getDefaultDisplay();
    }

    public MyAlertDialog builder() {
        View inflate = LayoutInflater.from(this.context).inflate(R.layout.toast_view_alertdialog, (ViewGroup) null);
        this.lLayout_bg = (LinearLayout) inflate.findViewById(R.id.lLayout_bg);
        this.txt_title = (TextView) inflate.findViewById(R.id.txt_title);
        this.txt_title.setVisibility(8);
        this.txt_msg = (TextView) inflate.findViewById(R.id.txt_msg);
        this.txt_msg.setVisibility(8);
        this.edittxt_result = (EditText) inflate.findViewById(R.id.edittxt_result);
        this.edittxt_result.setVisibility(8);
        this.dialog_Group = (LinearLayout) inflate.findViewById(R.id.dialog_Group);
        this.dialog_Group.setVisibility(8);
        this.dialog_marBottom = (ImageView) inflate.findViewById(R.id.dialog_marBottom);
        this.btn_neg = (TextView) inflate.findViewById(R.id.btn_neg);
        this.btn_pos = (TextView) inflate.findViewById(R.id.btn_pos);
        this.negLL = (LinearLayout) inflate.findViewById(R.id.ll_left);
        this.posLL = (LinearLayout) inflate.findViewById(R.id.ll_right);
        this.img_line = (ImageView) inflate.findViewById(R.id.img_line);
        this.img_line.setVisibility(8);
        this.dialog = new Dialog(this.context, R.style.AlertDialogStyle);
        this.dialog.setContentView(inflate);
        LinearLayout linearLayout = this.lLayout_bg;
        double width = this.display.getWidth();
        Double.isNaN(width);
        linearLayout.setLayoutParams(new FrameLayout.LayoutParams((int) (width * 0.6d), -2));
        return this;
    }

    public TextView getPositiveButton() {
        return this.btn_pos;
    }

    public TextView getNegativeButton() {
        return this.btn_neg;
    }

    public EditText getContentEditText() {
        return this.edittxt_result;
    }

    public MyAlertDialog setTitle(String str) {
        this.showTitle = true;
        if ("".equals(str)) {
            this.txt_title.setText(this.context.getString(R.string.prompt));
        } else {
            this.txt_title.setText(str);
        }
        return this;
    }

    public MyAlertDialog setEditText(String str) {
        this.showEditText = true;
        if ("".equals(str)) {
            this.edittxt_result.setHint(this.context.getString(R.string.input_code_hint));
        } else {
            this.edittxt_result.setHint(str);
        }
        return this;
    }

    public MyAlertDialog setEditTextContent(String str) {
        this.showEditText = true;
        if (!TextUtils.isEmpty(str)) {
            this.edittxt_result.setText(str);
            Editable text = this.edittxt_result.getText();
            Selection.setSelection(text, text.length());
        }
        return this;
    }

    public MyAlertDialog setEditType(int i) {
        this.edittxt_result.setInputType(i);
        return this;
    }

    public String getResult() {
        return this.edittxt_result.getText().toString();
    }

    public MyAlertDialog setMsg(String str) {
        this.showMsg = true;
        if ("".equals(str)) {
            this.txt_msg.setText(this.context.getString(R.string.input_code_hint));
        } else {
            this.txt_msg.setText(Html.fromHtml(str));
        }
        return this;
    }

    public MyAlertDialog setView(View view) {
        this.showLayout = true;
        if (view == null) {
            this.showLayout = false;
        } else {
            this.dialog_Group.addView(view, -1, -1);
        }
        return this;
    }

    public MyAlertDialog setCancelable(boolean z) {
        this.dialog.setCancelable(z);
        return this;
    }

    public MyAlertDialog setCanceledOnTouchOutside(boolean z) {
        this.dialog.setCanceledOnTouchOutside(z);
        return this;
    }

    public MyAlertDialog setPositiveButton(String str, final View.OnClickListener onClickListener) {
        this.showPosBtn = true;
        if ("".equals(str)) {
            this.btn_pos.setText(this.context.getString(R.string.confirm));
        } else {
            this.btn_pos.setText(str);
        }
        this.btn_pos.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.MyAlertDialog.1
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                onClickListener.onClick(view);
                MyAlertDialog.this.dialog.dismiss();
            }
        });
        return this;
    }

    public MyAlertDialog setPositiveButton(String str, final View.OnClickListener onClickListener, final boolean z) {
        this.showPosBtn = true;
        if ("".equals(str)) {
            this.btn_pos.setText(this.context.getString(R.string.confirm));
        } else {
            this.btn_pos.setText(str);
        }
        this.btn_pos.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.MyAlertDialog.2
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                onClickListener.onClick(view);
                if (z) {
                    MyAlertDialog.this.dialog.dismiss();
                }
            }
        });
        return this;
    }

    public MyAlertDialog setNegativeButton(String str, final View.OnClickListener onClickListener) {
        this.showNegBtn = true;
        if ("".equals(str)) {
            this.btn_neg.setText(this.context.getString(R.string.cancel));
        } else {
            this.btn_neg.setText(str);
        }
        this.btn_neg.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.MyAlertDialog.3
            @Override // android.view.View.OnClickListener
            public void onClick(View view) {
                onClickListener.onClick(view);
                MyAlertDialog.this.dialog.dismiss();
            }
        });
        return this;
    }

    private void setLayout() {
        if (!this.showTitle && !this.showMsg) {
            this.txt_title.setText(this.context.getString(R.string.prompt));
            this.txt_title.setVisibility(0);
        }
        if (this.showTitle) {
            this.txt_title.setVisibility(0);
        }
        if (this.showEditText) {
            this.edittxt_result.setVisibility(0);
        }
        if (this.showMsg) {
            this.txt_msg.setVisibility(0);
        }
        if (this.showLayout) {
            this.dialog_Group.setVisibility(0);
            this.dialog_marBottom.setVisibility(8);
        }
        if (!this.showPosBtn && !this.showNegBtn) {
            this.btn_pos.setText(this.context.getString(R.string.confirm));
            this.posLL.setVisibility(0);
            this.btn_pos.setOnClickListener(new View.OnClickListener() { // from class: com.jxw.launcher.view.MyAlertDialog.4
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    MyAlertDialog.this.dialog.dismiss();
                }
            });
        }
        if (this.showPosBtn && this.showNegBtn) {
            this.posLL.setVisibility(0);
            this.negLL.setVisibility(0);
            this.img_line.setVisibility(0);
        }
        if (this.showPosBtn && !this.showNegBtn) {
            this.posLL.setVisibility(0);
            this.negLL.setVisibility(8);
            this.img_line.setVisibility(8);
        }
        if (this.showPosBtn || !this.showNegBtn) {
            return;
        }
        this.posLL.setVisibility(8);
        this.negLL.setVisibility(0);
        this.img_line.setVisibility(8);
    }

    public void show() {
        AutoSize.autoConvertDensity((Activity) this.context, 1280.0f, true);
        setLayout();
        Dialog dialog = this.dialog;
        if (dialog != null) {
            dialog.show();
        }
    }

    public void dismiss() {
        try {
            if (this.dialog != null && this.dialog.isShowing()) {
                this.dialog.dismiss();
            }
            this.dialog = null;
        } catch (Exception unused) {
        }
    }
}
